#include "AnimatedModel.h"

/*
	This function attempts to load the requested .x file from filename
	If it fails (probably cannot find the file) it returns false
	The startAnimation optionally allows the first animation to play to be set
*/
bool AnimatedModel::LoadXFile(const std::string &filename,int startAnimation)
{
	// We only support one entity so if it already exists delete it
	if (m_entity)
	{
		delete m_entity;
		m_entity=0;
	}

	// Create the entity
	m_entity=new CXFileEntity(m_d3dDevice);
	if (!m_entity->Load(filename))
	{
		delete m_entity;
		m_entity=0;
		return false;
	}

	m_entity->SetAnimationSet(startAnimation);

	// Set the camera so it is looking at the entity
	D3DXVECTOR3 pos=m_entity->GetInitialCameraPosition();
	m_camera->SetPosition(pos);
	m_camera->SetYawPitchRoll(0,0,0);

	return true;
}